package com.huawei.smartcity0102.news;

import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.huawei.smartcity0102.Base;
import com.huawei.smartcity0102.R;
import com.huawei.smartcity0102.home.F_Home;
import com.huawei.smartcity0102.model.newlist;
import com.huawei.smartcity0102.util.Ad;
import com.huawei.smartcity0102.util.Http;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZengYunyi
 * @description:
 * @date :2022/1/2 13:54
 */
public class F_News extends Base {
    private RecyclerView rv;

    @Override
    protected int layId() {
        return R.layout.rv;
    }

    @Override
    protected String title() {
        return "新闻";
    }

    @Override
    protected Boolean back() {
        return false;
    }

    @Override
    protected Boolean bottom() {
        return true;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
        List<newlist.RowsDTO> list2=new ArrayList<>();
        list2.addAll(F_Home.newlist);
        Ad<newlist.RowsDTO> ad3 = new Ad<newlist.RowsDTO>(R.layout.r_base, list2) {
            private void initView(View iv) {
                ig = (ImageView) iv.findViewById(R.id.ig);
                tv1 = (TextView) iv.findViewById(R.id.tv1);
                tv2 = (TextView) iv.findViewById(R.id.tv2);
                tv3 = (TextView) iv.findViewById(R.id.tv3);
                tv4 = (TextView) iv.findViewById(R.id.tv4);
                tv5 = (TextView) iv.findViewById(R.id.tv5);
                web = (WebView) iv.findViewById(R.id.web);
            }

            private WebView web;
            private TextView tv5;
            private TextView tv4;
            private TextView tv3;
            private TextView tv2;
            private TextView tv1;
            private ImageView ig;

            @Override
            protected void initD(View vi, newlist.RowsDTO data, int p) {
                initView(vi);
                Glide.with(ig.getContext()).load(Http.base + data.getCover()).into(ig);
                tv1.setText(data.getTitle());
                tv2.setVisibility(View.GONE);
                tv5.setVisibility(View.GONE);
                tv3.setText("评论总数"+data.getTitle());
                web.setVisibility(View.VISIBLE);
                tv4.setText("发布时间"+data.getCreateTime());
                web.loadDataWithBaseURL(Http.base,data.getContent(),"text/html","utf-8",null);
                vi.setOnClickListener(v->{
                    F_Home.news=data;
                    add(new F_News1());
                });
            }
        };
        rv.setAdapter(ad3);
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    private void initView(View iv) {
        rv = (RecyclerView) iv.findViewById(R.id.rv);
    }
}
